<%@ page import="com.hll.util.StringUtil" %>
<%@ page import="com.hll.model.Book" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>新增图书</title>
    <link href="<%=request.getContextPath()%>/static/style/reset.css" rel="stylesheet" type="text/css">
    <link href="<%=request.getContextPath()%>/static/style/common.css" rel="stylesheet" type="text/css">
    <link href="<%=request.getContextPath()%>/static/style/mybook.css" rel="stylesheet" type="text/css">
    <link href="<%=request.getContextPath()%>/static/style/edit_book.css" rel="stylesheet" type="text/css">
    <script>
        function saveBook() {
            var editBookObj = document.getElementById("editBook");
            var isSubmitForm = true;

            var nameObj = document.getElementById("name");
            var bookNameValue = nameObj.value;
            if (!bookNameValue.trim()) {
                isSubmitForm = false;
                nameObj.style.border = "1px dashed #EB340A";
                document.getElementById("name_error_message").style.display = "inline";
            } else {
                nameObj.style.cssText = "border: 1px solid #858585;width: 410px;";
                document.getElementById("name_error_message").style.display = "none";
            }


            var authorObj = document.getElementById("author");
            var authorValue = authorObj.value;

            if (!authorValue.trim()) {
                isSubmitForm = false;
                authorObj.style.border="1px dashed #EB340A";
                document.getElementById("author_error_message").style.display = "inline";
            } else {
                authorObj.style.cssText = "border: 1px solid #858585;";
                document.getElementById("author_error_message").style.display = "none";
            }
            if (isSubmitForm) {
                editBookObj.submit();
            }
        }
    </script>
</head>
<body>
<div class="warpper" id="editBookPage">
    <div id="headerWarpper">
        <div id="header">
            <div class="logo">图书分享</div>
            <div class="menu">
                <ul>
                    <li><a href="#">我的图书</a></li>
                    <li><a href="#" style="background-color: #2B6C85;">全部图书</a></li>
                </ul>
            </div>
            <div class="tool">
                <input name="searchKey" type="text">
                <img class="search button" src="<%=request.getContextPath()%>/static/images/BTN_Search_30x30.png"/>
                <img class="role_switch_button" src="<%=request.getContextPath()%>/static/images/BTN_SwitchRole_User_35x35.png"/>
            </div>
        </div>
    </div>
    <%
        Book book = (Book)request.getAttribute("book");
    %>
    <div id="breadcrumb">
        <ul>
            <li>当前位置&nbsp;&nbsp;</li>
            <li><a href="#"></a>我的图书&nbsp;&nbsp;&gt;</li>
            <li><a href="#">
                <%
                    if (book.getId() > 0) {
                %>
                修改图书
                <%
                } else{
                %>
                创建图书
                <%
                    }
                %>
            </a></li>
        </ul>
    </div>
    <div class="main" id="editBookMain">
        <form id="editBook" method="POST" action="<%=request.getContextPath()%>/saveBook.action">
            <div class="info_area">
                <div class="title">1、上传图书封面照片</div>
                <div class="show_image"></div>
            </div>
            <div class="info_area">
                <div class="title">2、填写书籍资料</div>

                <ul>
                    <li>
                        <input type="hidden" name="id" value="<%=book.getId()%>">
                        <label>书名&nbsp;&nbsp;&nbsp;&nbsp;</label>
                        <span><input type="text" id="name" name="name" style="width: 410px" value="<%=StringUtil.doWithNull(book.getName())%>"/></span>
                        <span class="error_message" id="name_error_message" >书名不能为空！</span>
                    </li>
                    <li>
                        <label>作者&nbsp;&nbsp;&nbsp;&nbsp;</label>
                        <span><input type="text" id="author" name="author" value="<%=StringUtil.doWithNull(book.getAuthor())%>"></span>
                        <span class="error_message" id="author_error_message">作者不能为空！</span>
                    </li>
                    <li>
                        <label>简介&nbsp;&nbsp;&nbsp;&nbsp;</label>
                        <span><textarea rows="5" cols="5" name="desc"><%=StringUtil.doWithNull(book.getDesc())%></textarea>&nbsp;&nbsp;（选题）</span>
                    </li>
                </ul>
                <div class="button" onclick="saveBook()">保存图片</div>
            </div>
        </form>
    </div>
</div>
</body>
</html>
